﻿@{
    ViewBag.Title = "Index";
    Layout = null;
}

<!DOCTYPE html>
<html>
    <head>
        <meta name="viewport" content="width=device-width" />
        <title>商户派送地址管理</title>
        <link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.2/themes/default/easyui.css">
        <link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.2/themes/icon.css">
        <link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.2/demo.css">
        <link href="~/Content/Styles/Manage_Order.css" rel="stylesheet" />
        <script type="text/javascript" src="~/Content/jquery-easyui-1.4.2/jquery.min.js"></script>
        <script type="text/javascript" src="~/Content/jquery-easyui-1.4.2/jquery.easyui.min.js"></script>
        <script src="~/Content/jquery-easyui-1.4.2/locale/easyui-lang-zh_CN.js"></script>

        <script>
            $(function () {
                init();
            });

            // 初始化列表
            function init() {
                $('#load').datagrid({
                    iconCls: 'icon-user',
                    loadMsg: '数据加载中...',
                    nowrap: true,
                    autoRowHeight: true,
                    striped: true,
                    url: '/AddressManagement/getAdderss',
                    sortName: 'AddId',
                    sortOrder: 'asc',
                    border: true,
                    remoteSort: false,
                    idField: 'AddId',
                    pageSize: 10,
                    singleSelect: true,
                    pagination: true,
                    rownumbers: true,
                    columns: [[
                        { field: 'AddId', title: '地址编号', width: 100, sortable: true, align: 'center' },
                        { field: 'AddName', title: '地址', width: 450, sortable: true, align: 'center' },
                    ]],
                    toolbar: '#tb'
                });
            }

            // 新增地址
            function Add() {
                $("#add").window('open');
                $("#addAdderss").textbox("setValue", "")
            }

            // 新增地址保存
            function AddSave() {
                var postdata = {
                    AddName: $("#addAdderss").textbox("getValue"),
                }
                $.post("/AddressManagement/Updata?Tag=1", postdata, function (resp) {
                    if (resp == "ok") {
                        $.messager.alert("友情提示", "新增成功");
                        $("#add").window('close');
                        init();
                    } else {
                        $.messager.alert("友情提示", "新增失败！", "info")
                    }
                });
            }

            var addID; // 地址ID
            // 修改前赋值
            function Update() {
                var data = $("#load").datagrid("getSelections");
                if (data.length != 1) {
                    $.messager.alert("友情提示", "每次只能修改一行数据！", "info")
                } else {
                    addID = data[0].AddId;
                    $("#updata").window('open');
                    $("#updataAdderss").textbox("setValue", data[0].AddName);
                }
            }

            // 保存修改后的数据
            function updataSave() {
                var postdata = {
                    AddId: addID,
                    AddName:$("#updataAdderss").textbox("getValue")
                }
                $.post("/AddressManagement/Updata?Tag=2", postdata, function (resp) {
                    if (resp == "ok") {
                        $.messager.alert("友情提示", "修改成功");
                        $("#updata").window('close');
                        init();
                    } else {
                        $.messager.alert("友情提示", "修改失败！", "info")
                    }
                });
            }

            // 删除
            function Delete() {
                var data = $("#load").datagrid("getSelections");
                if (data.length != 1) {
                    $.messager.alert("友情提示", "每次只能删除一条数据！", "info")
                } else {
                    var postdata = {
                        AddId: data[0].AddId,
                        AddName: data[0].AddName,
                    }
                    $.post("/AddressManagement/Updata?Tag=3", postdata, function (resp) {
                        if (resp == "ok") {
                            $.messager.alert("友情提示", "删除成功");
                            init();
                        } else {
                            $.messager.alert("友情提示", "删除失败！", "info")
                        }
                    });
                }
            }
        </script>
    </head>
    <body style="padding: 0;">
        <!--工具栏S-->
        <div id="tb" style="padding: 5px; height: auto">
            <div style="margin-bottom: 5px">
                <a href="#" class="easyui-linkbutton" iconcls="icon-add" onclick="Add()">新增地址</a>&nbsp;
                <a href="#" id="xiugai" class="easyui-linkbutton" iconcls="icon-edit" onclick="Update()">修改地址</a>&nbsp;
                <a href="#" id="shanc" class="easyui-linkbutton" iconcls="icon-cut" onclick="Delete()">删除地址</a>&nbsp;
                <hr style="margin-top: 5px" />
            </div>
        </div>
        <!--工具栏E-->

        <!--表格加载S-->
        <div>
            <table id="load" style="width: auto;"></table>
        </div>
        <!--表格加载E-->

        <!--新增地址S-->
        <div id="add" class="easyui-window" title="新增地址" data-options="modal:true,closed:true,iconCls:'icon-save'" >
            <table>
                <tr>
                    <td>地址：</td>
                    <td><input id="addAdderss" class="easyui-textbox" type="text" data-options="multiline:true"  style="width:700px;height:50px;"/></td>
                </tr>
                <tr style="text-align:center">
                    <td colspan="2"><a href="#" class="easyui-linkbutton" iconcls="icon-ok" onclick="AddSave()">保存</a>&nbsp;</td>
                </tr>
            </table>
        </div>
        <!--新增地址E-->

        <!--修改地址S-->
        <div id="updata" class="easyui-window" title="修改地址" data-options="modal:true,closed:true,iconCls:'icon-save'" >
            <table>
                <tr>
                    <td>地址：</td>
                    <td><input id="updataAdderss" class="easyui-textbox" type="text" data-options="multiline:true"  style="width:700px;height:50px;"/></td>
                </tr>
                <tr style="text-align:center">
                    <td colspan="2"><a href="#" class="easyui-linkbutton" iconcls="icon-ok" onclick="updataSave()">保存</a>&nbsp;</td>
                </tr>
            </table>
        </div>
        <!--修改地址E-->
    </body>
</html>
